package com.piggy.sys.controller;

import com.piggy.common.core.constant.SecurityConstants;
import com.piggy.common.core.domain.R;
import com.piggy.common.core.utils.FeignResultUtils;
import com.piggy.common.core.web.controller.BaseController;
import com.piggy.common.core.web.page.TableDataInfo;
import com.piggy.common.log.annotation.LogiLog;
import com.piggy.common.log.enums.BusinessType;
import com.piggy.logi.sys.api.RemoteLogiPriceSegService;
import com.piggy.logi.sys.api.bo.LogiPriceSegEditBo;
import com.piggy.logi.sys.api.bo.LogiPriceSegQueryBo;
import com.piggy.logi.sys.api.vo.LogiPriceSegExtVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
 * 分段价格Controller
 *
 * @author piggy
 * @date 2023-08-14
 */
@Api(value = "分段价格控制器", tags = {"分段价格管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/logi/seg")
public class LogiPriceSegController extends BaseController {

    @Resource
    private RemoteLogiPriceSegService iLogiPriceSegService;

    /**
     * 查询分段价格列表
     */
    @ApiOperation("查询分段价格列表")
    //@SaCheckPermission("sys:seg:list")
    @GetMapping("/list")
    public TableDataInfo<LogiPriceSegExtVo> list(@Validated LogiPriceSegQueryBo bo) {
        TableDataInfo<LogiPriceSegExtVo> page = iLogiPriceSegService.innerList(bo, SecurityConstants.INNER);
        FeignResultUtils.throwIfFailed(page);
        return page;
    }

    /**
     * 获取分段价格详细信息
     */
    @ApiOperation("获取分段价格详细信息")
    //@SaCheckPermission("sys:seg:query")
    @GetMapping("/{id}")
    public R<LogiPriceSegExtVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        R<LogiPriceSegExtVo> r = iLogiPriceSegService.innerInfo(id, SecurityConstants.INNER);
        FeignResultUtils.throwIfFailed(r);
        return r;
    }

    /**
     * 新增分段价格
     */
    @ApiOperation("新增分段价格")
    //@SaCheckPermission("sys:seg:add")
    @LogiLog(title = "分段价格", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<LogiPriceSegExtVo> add(@Validated @RequestBody LogiPriceSegEditBo bo) {
        R<LogiPriceSegExtVo> r = iLogiPriceSegService.innerAdd(bo, SecurityConstants.INNER);
        FeignResultUtils.throwIfFailed(r);
        return r;
    }

    /**
     * 修改分段价格
     */
    @ApiOperation("修改分段价格")
    //@SaCheckPermission("sys:seg:edit")
    @LogiLog(title = "分段价格", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<LogiPriceSegExtVo> edit(@Validated @RequestBody LogiPriceSegEditBo bo) {
        R<LogiPriceSegExtVo> r = iLogiPriceSegService.innerEdit(bo, SecurityConstants.INNER);
        FeignResultUtils.throwIfFailed(r);
        return r;
    }

    /**
     * 删除分段价格
     */
    @ApiOperation("删除分段价格")
    //@SaCheckPermission("sys:seg:remove")
    @LogiLog(title = "分段价格" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Integer> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        R<Integer> r = iLogiPriceSegService.innerRemove(ids, SecurityConstants.INNER);
        FeignResultUtils.throwIfFailed(r);
        return r;
    }
}
